package com.service.log;


import com.common.ResultUtil;
import com.entity.OperationLog;
import com.facade.log.IOperationLogFacadeCUD;
import com.mapper.CustomMapper;
import com.mapper.OperationLogMapper;
import com.service.CustomServiceCUD;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Date;

@Service
public class OperationLogServiceCUD extends CustomServiceCUD<OperationLog> implements IOperationLogFacadeCUD {

    @Resource
    private OperationLogMapper mapper;

    @Override
    protected CustomMapper<OperationLog> initMapper() {
        return mapper;
    }

    @Override
    public ResultUtil addOperationLog(Serializable managerId, Integer type, String content) {
        ResultUtil resultUtil = ResultUtil.newInstance();
        OperationLog operationLog = new OperationLog();
        operationLog.setManagerId((Long) managerId);
        operationLog.setType(type);
        operationLog.setContent(content);
        operationLog.setCreated(new Date());
        add(operationLog);
        return resultUtil;
    }

    @Override
    public ResultUtil deleteOperationLog(Serializable[] ids) {
        ResultUtil resultUtil = ResultUtil.newInstance();
        if (null != ids && ids.length > 0) {
            deleteByPropertyIn("id", Arrays.asList(ids));
            resultUtil.setMessage("删除成功");
        }
        return resultUtil;
    }
}